﻿using System;
using System.Collections.Generic;
using System.Linq;
using Blog.Core.Entities;

namespace Blog.Presentation.Models.Dislpay
{
    public class ArticleDto
    {
        public ArticleDto(Article article)
        {
            Id = article.Id;
            Date = article.Date;
            Title = article.Title;
            Text = article.Content.Substring(0,100) + "...";
            Views = article.Views;
           
        }

        public long Id { get; set; }
        public DateTime Date { get; set; }
        public string Title { get; set; }
        public string Text { get; set; }
        public long Views { get; set; }
        public long ComentsNr { get; set; }

        public static List<ArticleDto> FromAListOfArticles(IEnumerable<Article> articles)
        {
            return
                articles.Select(
                    article =>
                    new ArticleDto(article))
                    .ToList();
        }
    }
}